package ru.spies.entities;

import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST;
import static javax.persistence.CascadeType.REFRESH;
import static javax.persistence.FetchType.EAGER;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * The persistent class for the tasks database table.
 * 
 */
@Entity
@Table(name="tasks")
@NamedQuery(name="Task.findAll", query="SELECT t FROM Task t")
public class Task implements Serializable, ITableClass {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(unique=true, nullable=false)
	private Integer id;

	@Column(nullable=false, length=2147483647)
	private String name;

	@Column(length=1)
	private String status;

	//bi-directional many-to-one association to Agentsandtask
	@OneToMany(mappedBy="task", fetch = EAGER, cascade = { REFRESH, MERGE, PERSIST })
	private List<Agentsandtask> agentsandtasks;

	//bi-directional many-to-one association to Document
	@OneToMany(mappedBy="task", fetch = EAGER, cascade = { REFRESH, MERGE, PERSIST })
	private List<Document> documents;

	//bi-directional many-to-one association to Country
	@ManyToOne(fetch = EAGER, cascade = {REFRESH, MERGE})
	@JoinColumn(name="id_country", nullable=false)
	private Country country;

	//bi-directional many-to-one association to Importance
	@ManyToOne(fetch=EAGER, cascade = {REFRESH, MERGE})
	@JoinColumn(name="id_importance")
	private Importance importance;

	//bi-directional many-to-one association to TaskType
	@ManyToOne(fetch=EAGER, cascade = {REFRESH, MERGE})
	@JoinColumn(name="id_type")
	private TaskType taskType;

	private Object paramForFindQuery=null;
	
	public Task() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStatus() {
		return this.status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public List<Agentsandtask> getAgentsandtasks() {
		return this.agentsandtasks;
	}

	public void setAgentsandtasks(List<Agentsandtask> agentsandtasks) {
		this.agentsandtasks = agentsandtasks;
	}

	public Agentsandtask addAgentsandtask(Agentsandtask agentsandtask) {
		getAgentsandtasks().add(agentsandtask);
		agentsandtask.setTask(this);

		return agentsandtask;
	}

	public Agentsandtask removeAgentsandtask(Agentsandtask agentsandtask) {
		getAgentsandtasks().remove(agentsandtask);
		agentsandtask.setTask(null);

		return agentsandtask;
	}

	public List<Document> getDocuments() {
		return this.documents;
	}

	public void setDocuments(List<Document> documents) {
		this.documents = documents;
	}

	public Document addDocument(Document document) {
		getDocuments().add(document);
		document.setTask(this);

		return document;
	}

	public Document removeDocument(Document document) {
		getDocuments().remove(document);
		document.setTask(null);

		return document;
	}

	public Country getCountry() {
		return this.country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	public Importance getImportance() {
		return this.importance;
	}

	public void setImportance(Importance importance) {
		this.importance = importance;
	}

	public TaskType getTaskType() {
		return this.taskType;
	}

	public void setTaskType(TaskType taskType) {
		this.taskType = taskType;
	}

	@Override
	public void setParamForFindQuery(Object param) {
		paramForFindQuery=param;		
	}

	@Override
	public Object getParamForFindQuery() {
		return paramForFindQuery;
	}

	@Override
	public ITableClass createThisObject() {
		return new Task();
	}

	@Override
	public String getQueryForFind() {
		return "SELECT x FROM Task x WHERE x.id = :param";
	}

}